package api

import (
	"github.com/kataras/iris/v12"
	"gorm.io/driver/sqlite"
	"gorm.io/gorm"
)

const (
	dataSourceName = "bettle.db"
)

// App 应用程序
type App struct {
	gormDB  *gorm.DB
	irisAPP *iris.Application
}

func Init() *App {
	gormDB, err := gorm.Open(sqlite.Open(dataSourceName), &gorm.Config{})
	if err != nil {
		panic(err)
	}
	irisAPP := iris.New()
	return &App{
		gormDB:  gormDB,
		irisAPP: irisAPP,
	}
}

func (app *App) DB() *gorm.DB {
	return app.gormDB
}

func (app *App) Application() *iris.Application {
	return app.irisAPP
}

func (app *App) InitSrv() {
	initService(app)
}

func (app *App) Regist() {
	regist(app)
}
